package com.zhaoxi.project.sys.controller;

import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.project.sys.service.WorkFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


import java.util.Map;

/**
 * 流程数据处理
 */
@RestController
@RequestMapping("/sys/workflow")
public class WorkFlowController extends BaseService {

    @Autowired
    private WorkFlowService workFlowService;

    //  获列表
    @PreAuthorize("@ss.hasPermi('sys:workflow:list')")
    @GetMapping("/getList")
    public PageData getList(Map map) {
        PageData pd = this.getPageData(map);
        //如果pageNum 和 pageSize 都是有值的，就是需要分页的
        if(pd.getLong("pageNum") != null && pd.getLong("pageSize") != null) {
            this.startPage();
        }

        return workFlowService.getList(pd);
    }

    //  获行数
    @PreAuthorize("@ss.hasPermi('sys:workflow:list')")
    @GetMapping("/getCount")
    public PageData getCount(Map map) {
        PageData pd = this.getPageData(map);
        return workFlowService.getCount(pd);
    }

    //新增数据
    @PreAuthorize("@ss.hasAnyPermi('sys:workflow:add')")
    @Log(title = "流程管理",businessType = BusinessType.INSERT)
    @PostMapping
    public PageData add(@RequestBody Map map) {
        PageData pd = this.getPageData(map);
        return workFlowService.add(pd);
    }

    //  修改数据
    @PreAuthorize("@ss.hasPermi('sys:workflow:edit')")
    @Log(title = "样例管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public PageData edit(@RequestBody Map map) {
        PageData pd = this.getPageData(map);
        return workFlowService.edit(pd);
    }

    //  删除数据
    @PreAuthorize("@ss.hasPermi('sys:workflow:del')")
    @Log(title = "样例管理", businessType = BusinessType.DELETE)
    @DeleteMapping("id/{id}")
    public PageData del(@PathVariable Long id) {
        return workFlowService.del(id);
    }



    //============子表数据增删改查================
    //  获取列表数据
//    @PreAuthorize("@ss.hasPermi('sys:workflow:list')")
//    @GetMapping("/getLineList")
//    public AjaxResult getLineList(Map map) {
//        PageData pd = this.getPageData(map);
//        List<PageData> list = workFlowService.getLineList(pd);
//        return this.success(list);
//    }

    //  获列表表数据
    @PreAuthorize("@ss.hasPermi('sys:workflow:list')")
    @GetMapping("/getLineList")
    public PageData getLineList(Map map) {
        PageData pd = this.getPageData(map);
        //如果 pageNum 和 pageSize 都是有值的，就是需要分页的
        if (pd.getLong("pageNum") != null && pd.getLong("pageSize") != null){
            this.startPage();
        }
        return this.responses(workFlowService.getLineList(pd));
    }

    //  新增数据
    @PreAuthorize("@ss.hasPermi('sys:workflow:add')")
    @Log(title = "样例管理", businessType = BusinessType.INSERT)
    @PostMapping("/line")
    public PageData addLine(@RequestBody Map map) {
        PageData pd = this.getPageData(map);
        return workFlowService.addLine(pd);
    }

    //  修改数据
    @PreAuthorize("@ss.hasPermi('sys:workflow:edit')")
    @Log(title = "样例管理", businessType = BusinessType.UPDATE)
    @PutMapping("/line")
    public PageData editLine(@RequestBody Map map) {
        PageData pd = this.getPageData(map);
        return workFlowService.editLine(pd);
    }
    //  删除
    @PreAuthorize("@ss.hasPermi('sys:workflow:del')")
    @Log(title = "样例管理", businessType = BusinessType.DELETE)
    @DeleteMapping("lineId/{lineId}")
    public PageData delLine(@PathVariable Long lineId) {
        PageData pd = this.getPageData();
        pd.put("lineId",lineId);
        return workFlowService.delLine(pd);
    }
    //审批+权限
    @PostMapping("authorize/{lineId}")
    public PageData authorize(@PathVariable Long lineId, int result) {
        return workFlowService.authorize(lineId,result);
    }


//    //  获行数
//    @PreAuthorize("@ss.hasPermi('sys:workflow:list')")
//    @GetMapping("/getLineCount")
//    public AjaxResult getLineCount(Map map) {
//        PageData pd = this.getPageData(map);
//        return this.success(workFlowService.getLineCount(pd));
//    }
//
//    //  新增数据
//    @PreAuthorize("@ss.hasPermi('sys:workflow:add')")
//    @Log(title = "样例管理", businessType = BusinessType.INSERT)
//    @PostMapping("/line")
//    public AjaxResult addLine(@RequestBody Map map) {
//        PageData pd = this.getPageData(map);
//        return toAjax(workFlowService.addLine(pd));
//    }
//
//    //  修改
//    @PreAuthorize("@ss.hasPermi('sys:workflow:edit')")
//    @Log(title = "样例管理", businessType = BusinessType.UPDATE)
//    @PutMapping("/line")
//    public AjaxResult editLine(@RequestBody Map map) {
//        PageData pd = this.getPageData(map);
//        return toAjax(workFlowService.editLine(pd));
//    }
//
//    //  删除
//    @PreAuthorize("@ss.hasPermi('sys:workflow:del')")
//    @Log(title = "样例管理", businessType = BusinessType.DELETE)
//    @DeleteMapping("lineId/{lineId}")
//    public AjaxResult delLine(@PathVariable Long lineId) {
//        return toAjax(workFlowService.delLine(lineId));
//    }



}
